<!DOCTYPE html>
<!-- saved from url=(0052)https://www.cnblogs.com/mycls/articles/15945845.html -->
<html lang="zh-cn" style="--olcb-folder-code-block-max-height:80vh;"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="origin-when-cross-origin">
    <meta name="description" content="工作中用到低功耗蓝牙，在网上找了一圈自己总结了一下 最终效果 开发环境：Visual Studio2019 Win10 参考文章 https://www.cnblogs.com/webtojs/p/9">
    <meta property="og:description" content="工作中用到低功耗蓝牙，在网上找了一圈自己总结了一下 最终效果 开发环境：Visual Studio2019 Win10 参考文章 https://www.cnblogs.com/webtojs/p/9">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园</title>
    <link id="favicon" rel="shortcut icon" href="https://common.cnblogs.com/favicon.svg" type="image/svg+xml">
    
    <style>#home :not(.cnblogs_code):not(.cnblogs_Highlighter)>pre:not([highlighted]):not([class*="brush:"]) code:not(.hljs), :not(.cnblogs_code):not(.cnblogs_Highlighter)>pre:not([highlighted]):not([class*="brush:"]) code:not(.hljs) {background: rgb(245, 245, 245);
        padding: 12px;
        border: 1px solid rgb(204, 204, 204);
        border-radius: 3px;
        border-color: transparent;
        color: rgb(68, 68, 68);
        font-family: "Courier New", sans-serif;
        font-size: 12px</style><link rel="stylesheet" href="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/blog-common.min.css">
    

    <link id="MainCss" rel="stylesheet" href="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/bundle-lessismoreright.min.css">
        <link id="highlighter-theme-cnblogs" type="text/css" rel="stylesheet" href="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/cnblogs.css">
    
    
    <link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/bundle-lessismoreright-mobile.min.css">
    
    <link type="application/rss+xml" rel="alternate" href="https://www.cnblogs.com/mycls/rss">
    <link type="application/rsd+xml" rel="EditURI" href="https://www.cnblogs.com/mycls/rsd.xml">
    <link type="application/wlwmanifest+xml" rel="wlwmanifest" href="https://www.cnblogs.com/mycls/wlwmanifest.xml">
    <script type="text/javascript" async="" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/analytics.js.下载"></script><script>
        var currentBlogId = 193221;
        var currentBlogApp = 'mycls';
        var isLogined = false;
        var isBlogOwner = false;
        var skinName = 'LessIsMoreRight';
        var visitorUserId = '';
        var hasCustomScript = false;
        try {
            if (hasCustomScript && document.referrer && document.referrer.indexOf('baidu.com') >= 0) {
                Object.defineProperty(document, 'referrer', { value: '' });
                Object.defineProperty(Document.prototype, 'referrer', { get: function () { return ''; } });
            }
        } catch (error) { }
        window.cb_enable_mathjax = false;
        window.mathEngine = 0;
        window.codeHighlightEngine = 1;
        window.enableCodeLineNumber = false;
        window.codeHighlightTheme = 'cnblogs';
        window.darkModeCodeHighlightTheme = 'vs2015';
        window.isDarkCodeHighlightTheme = false;
        window.isDarkModeCodeHighlightThemeDark = true;
        window.isDisableCodeHighlighter = false;
        window.enableCodeThemeTypeFollowSystem = false;
    </script>
        <script>
            var currentPostDateAdded = '2022-02-28 15:33';
        </script>
    <script src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/jquery-2.2.0.min.js.下载"></script>
    <script src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/blog-common.min.js.下载"></script><style>.medium-zoom-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  opacity: 0;
  transition: opacity 300ms;
  will-change: opacity;
}

.medium-zoom--opened .medium-zoom-overlay {
  cursor: pointer;
  cursor: zoom-out;
  opacity: 1;
}

.medium-zoom-image {
  cursor: pointer;
  cursor: zoom-in;
  /*
    The `transition` is marked as "!important" for the animation to happen
    even though it's overriden by another inline `transition` style attribute.

    This is problematic with frameworks that generate inline styles on their
    images (e.g. Gatsby).

    See https://github.com/francoischalifour/medium-zoom/issues/110
   */
  transition: transform 300ms cubic-bezier(0.2, 0, 0.2, 1) !important;
}

.medium-zoom-image--hidden {
  visibility: hidden;
}

.medium-zoom-image--opened {
  position: relative;
  cursor: pointer;
  cursor: zoom-out;
  will-change: transform;
}
</style><script id="hljs-script" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/highlight.min.js.下载" type="text/javascript" async=""></script>
    

    
<meta http-equiv="origin-trial" content="Az6AfRvI8mo7yiW5fLfj04W21t0ig6aMsGYpIqMTaX60H+b0DkO1uDr+7BrzMcimWzv/X7SXR8jI+uvbV0IJlwYAAACFeyJvcmlnaW4iOiJodHRwczovL2RvdWJsZWNsaWNrLm5ldDo0NDMiLCJmZWF0dXJlIjoiUHJpdmFjeVNhbmRib3hBZHNBUElzIiwiZXhwaXJ5IjoxNjgwNjUyNzk5LCJpc1N1YmRvbWFpbiI6dHJ1ZSwiaXNUaGlyZFBhcnR5Ijp0cnVlfQ=="><meta http-equiv="origin-trial" content="A+USTya+tNvDPaxUgJooz+LaVk5hPoAxpLvSxjogX4Mk8awCTQ9iop6zJ9d5ldgU7WmHqBlnQB41LHHRFxoaBwoAAACLeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXN5bmRpY2F0aW9uLmNvbTo0NDMiLCJmZWF0dXJlIjoiUHJpdmFjeVNhbmRib3hBZHNBUElzIiwiZXhwaXJ5IjoxNjgwNjUyNzk5LCJpc1N1YmRvbWFpbiI6dHJ1ZSwiaXNUaGlyZFBhcnR5Ijp0cnVlfQ=="><meta http-equiv="origin-trial" content="A7FovoGr67TUBYbnY+Z0IKoJbbmRmB8fCyirUGHavNDtD91CiGyHHSA2hDG9r9T3NjUKFi6egL3RbgTwhhcVDwUAAACLeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZXRhZ3NlcnZpY2VzLmNvbTo0NDMiLCJmZWF0dXJlIjoiUHJpdmFjeVNhbmRib3hBZHNBUElzIiwiZXhwaXJ5IjoxNjgwNjUyNzk5LCJpc1N1YmRvbWFpbiI6dHJ1ZSwiaXNUaGlyZFBhcnR5Ijp0cnVlfQ=="><script src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/pubads_impl_2023021301.js.下载" async=""></script><link rel="preload" href="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/f.txt" as="script"><script type="text/javascript" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/f.txt"></script></head>
<body class="skin-lessismoreright has-navbar hljs-engine">
    <a name="top"></a>
    <div id="top_nav" class="navbar forpc">
        <nav id="nav_main" class="navbar-main">
            <ul id="nav_left" class="navbar-list navbar-left">
                <li class="navbar-branding">
                    <a href="https://www.cnblogs.com/" title="开发者的网上家园" role="banner">
                            <img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/logo.svg" alt="博客园Logo">
                    </a>
                </li>
                <li>
                    <a href="https://www.cnblogs.com/" onclick="countClicks(&#39;skin-navbar-sitehome&#39;)">首页</a>
                </li>
                <li>
                    <a href="https://news.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-news&#39;)">新闻</a>
                </li>
                <li>
                    <a href="https://q.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-q&#39;)">博问</a>
                </li>
                <li>
                    <a id="nav_brandzone" href="https://brands.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-brands&#39;)">专区</a>
                </li>
                <li>
                    <a href="https://ing.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-ing&#39;)">闪存</a>
                </li>
                <li>
                    <a href="https://edu.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-edu&#39;)">班级</a>
                </li>
            </ul>
            <ul id="nav_right" class="navbar-list navbar-right">
                <li>
                    <form id="zzk_search" class="navbar-search dropdown" action="https://zzk.cnblogs.com/s" method="get" role="search">
                        <input name="w" id="zzk_search_input" placeholder="代码改变世界" type="search" tabindex="3" autocomplete="off">
                        <button id="zzk_search_button" onclick="window.navbarSearchManager.triggerActiveOption()">
                            <img id="search_icon" class="focus-hidden" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/search.svg" alt="搜索">
                            <img class="hidden focus-visible" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/enter.svg" alt="搜索">
                        </button>
                        <ul id="navbar_search_options" class="dropdown-menu quick-search-menu">
                            <li tabindex="0" class="active" onclick="zzkSearch(event, document.getElementById(&#39;zzk_search_input&#39;).value)">
                                <div class="keyword-wrapper">
                                    <img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/search.svg" alt="搜索">
                                    <div class="keyword"></div>
                                </div>
                                <span class="search-area">所有博客</span>
                            </li>
                                    <li tabindex="1" onclick="zzkBlogSearch(event, &#39;mycls&#39;, document.getElementById(&#39;zzk_search_input&#39;).value)">
                                        <div class="keyword-wrapper">
                                            <img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/search.svg" alt="搜索">
                                            <div class="keyword"></div>
                                        </div>
                                        <span class="search-area">当前博客</span>
                                    </li>
                        </ul>
                    </form>
                </li>
                <li id="navbar_login_status" class="navbar-list">
                    <a class="navbar-user-info navbar-blog" href="https://i.cnblogs.com/EditPosts.aspx?opt=1" alt="写随笔" title="写随笔" style="display: none;">
                        <img id="new_post_icon" class="navbar-icon" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/newpost.svg" alt="写随笔">
                    </a>
                    <a id="navblog-myblog-icon" class="navbar-user-info navbar-blog" href="https://passport.cnblogs.com/GetBlogApplyStatus.aspx" alt="我的博客" title="我的博客" style="display: none;">
                        <img id="myblog_icon" class="navbar-icon" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/myblog.svg" alt="我的博客">
                    </a>
                    <a class="navbar-user-info navbar-message navbar-icon-wrapper" href="https://msg.cnblogs.com/" alt="短消息" title="短消息" style="display: none;">
                        <img id="msg_icon" class="navbar-icon" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/message.svg" alt="短消息">
                        <span id="msg_count" style="display: none"></span>
                    </a>
                    <a id="navbar_lite_mode_indicator" data-current-page="blog" style="display: none" href="javascript:void(0)" alt="简洁模式" title="简洁模式启用，您在访问他人博客时会使用简洁款皮肤展示">
                        <img class="navbar-icon" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/lite-mode-on.svg" alt="简洁模式">
                    </a>
                    <div id="user_info" class="navbar-user-info dropdown" style="display: none;">
                        <a class="dropdown-button" href="https://home.cnblogs.com/">
                            <img id="user_icon" class="navbar-avatar" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/avatar-default.svg" alt="用户头像">
                        </a>
                        <div class="dropdown-menu">
                            <a id="navblog-myblog-text" href="https://passport.cnblogs.com/GetBlogApplyStatus.aspx">我的博客</a>
                            <a href="https://home.cnblogs.com/">我的园子</a>
                            <a href="https://account.cnblogs.com/settings/account">账号设置</a>
                            <a href="javascript:void(0)" id="navbar_lite_mode_toggle" title="简洁模式会使用简洁款皮肤显示所有博客">
    简洁模式 <img id="navbar_lite_mode_on" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/lite-mode-check.svg" class="hide"><span id="navbar_lite_mode_spinner" class="hide">...</span>
</a>
                            <a href="javascript:void(0)" onclick="account.logout();">退出登录</a>
                        </div>
                    </div>
                    <a class="navbar-anonymous" href="https://account.cnblogs.com/signup" style="display: inline;">注册</a>
                    <a class="navbar-anonymous" href="javascript:void(0);" onclick="account.login()" style="display: inline;">登录</a>
                </li>
            </ul>
        </nav>
    </div>

    

    <div id="home">
    <div id="header">
        <div id="blogTitle">
            <div class="title"><a id="Header1_HeaderTitle" class="headermaintitle HeaderMainTitle" href="https://www.cnblogs.com/mycls/">蓝人</a>
</div>
<div class="subtitle"></div>

        </div>
        <div id="navigator">
            
<ul id="navList">
    <li id="nav_sitehome"><a id="blog_nav_sitehome" class="menu" href="https://www.cnblogs.com/">
博客园</a>
</li>
    <li id="nav_myhome">
<a id="blog_nav_myhome" class="menu" href="https://www.cnblogs.com/mycls/">
首页</a>
</li>
    <li id="nav_newpost">

<a id="blog_nav_newpost" class="menu" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">
新随笔</a>
</li>
    <li id="nav_contact">
<a id="blog_nav_contact" class="menu" href="https://msg.cnblogs.com/send/mycls">
联系</a></li>
    <li id="nav_rss">
<a id="blog_nav_rss" class="menu" href="javascript:void(0)" data-rss="https://www.cnblogs.com/mycls/rss/">
订阅</a></li>
    <li id="nav_admin">
<a id="blog_nav_admin" class="menu" href="https://i.cnblogs.com/">
管理</a>
</li>
</ul>

            <div class="blogStats">
                
<span id="stats_post_count">随笔 - 10&nbsp;</span>
<span id="stats_article_count">文章 - 1&nbsp;</span>
<span id="stats_comment_count">评论 - 4&nbsp;</span>
<span id="stats_total_view_count">阅读 - 
<span title="总阅读数: 11643">
11643</span></span>
            </div>
        </div>
    </div>
    <div id="main">
        <div id="mainContent">
            <div class="forFlow">
                <div id="post_detail">
    <div id="topics">
        <div class="post">
            <h1 class="postTitle">
                
<a id="cb_post_title_url" class="postTitle2 vertical-middle" href="https://www.cnblogs.com/mycls/articles/15945845.html">
    <span role="heading" aria-level="2">WinForm低功耗蓝牙通信BlueToothLE C#</span>
    
</a>

            </h1>
            <div class="clear"></div>
            <div class="postBody">
                <div id="cnblogs_post_body" class="blogpost-body cnblogs-markdown">
<p>工作中用到低功耗蓝牙，在网上找了一圈自己总结了一下</p>
<p>最终效果<br>
<img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/580303-20220228154946306-465128315.png" alt="image" loading="lazy" class="medium-zoom-image"></p>
<p>开发环境：Visual Studio2019  Win10</p>
<p><img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/580303-20220228154753161-1856315598.png" alt="image" loading="lazy" class="medium-zoom-image"><br>
<img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/580303-20220228154849741-768992519.png" alt="image" loading="lazy" class="medium-zoom-image"></p>
<p>参考文章<br>
<a href="https://www.cnblogs.com/webtojs/p/9675956.html" target="_blank" rel="noopener">https://www.cnblogs.com/webtojs/p/9675956.html</a><br>
<a href="https://blog.csdn.net/weixin_32673065/article/details/113578844?utm_medium=distribute.pc_relevant.none-task-blog-2" target="_blank" rel="noopener">https://blog.csdn.net/weixin_32673065/article/details/113578844?utm_medium=distribute.pc_relevant.none-task-blog-2</a><sub>default</sub>baidujs_baidulandingword~default-0.pc_relevant_aa&amp;spm=1001.2101.3001.4242.1&amp;utm_relevant_index=3</p>
<p>自己实现的库</p>
<p>using System;<br>
using System.Collections.Generic;<br>
using System.Linq;<br>
using System.Text;<br>
using System.Threading;<br>
using System.Threading.Tasks;<br>
using Windows.Devices.Bluetooth;<br>
using Windows.Devices.Bluetooth.GenericAttributeProfile;<br>
using Windows.Devices.Enumeration;<br>
using Windows.Security.Cryptography;</p>
<pre class="highlighter-hljs" highlighted="true"><code class="highlighter-hljs hljs language-csharp"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">LanBle</span>
{
    <span class="hljs-built_in">string</span> Mac { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-built_in">string</span> ServiceID { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-built_in">string</span> WriteID { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-built_in">string</span> ReadID { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> BluetoothLEDevice Device { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-comment">//存储检测到的主服务。</span>
    <span class="hljs-keyword">public</span> GattDeviceService Service { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-comment">//存储检测到的写特征对象。</span>
    <span class="hljs-keyword">public</span> GattCharacteristic WriteCharacteristic { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-comment">//存储检测到的通知特征对象。</span>
    <span class="hljs-keyword">public</span> GattCharacteristic NotifyCharacteristic { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">event</span> BleRev OnRev;
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">event</span> BleScanResult OnScanResult;
    List&lt;ScanResult&gt; ScanResults = <span class="hljs-keyword">new</span> List&lt;ScanResult&gt;();
    <span class="hljs-built_in">bool</span> flag = <span class="hljs-literal">false</span>;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">LanBle</span>()</span>
    {

    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-built_in">bool</span> <span class="hljs-title">DisConnect</span>()</span>
    {
        NotifyCharacteristic = <span class="hljs-literal">null</span>;
        WriteCharacteristic = <span class="hljs-literal">null</span>;
        Service?.Dispose();
        Service = <span class="hljs-literal">null</span>;
        Device?.Dispose();
        Device = <span class="hljs-literal">null</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Stop</span>()</span>
    {
        flag = <span class="hljs-literal">false</span>;
    }
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-built_in">bool</span> <span class="hljs-title">Find</span>(<span class="hljs-params"><span class="hljs-built_in">string</span> id</span>)</span>
    {
        <span class="hljs-keyword">var</span> x = <span class="hljs-keyword">from</span> a <span class="hljs-keyword">in</span> ScanResults <span class="hljs-keyword">where</span> a.ID == id <span class="hljs-keyword">select</span> a;
        <span class="hljs-keyword">if</span> (x == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; }
        <span class="hljs-keyword">return</span> x.Count() == <span class="hljs-number">1</span>;
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Scan</span>(<span class="hljs-params"><span class="hljs-built_in">int</span> timeOut = <span class="hljs-number">10</span></span>)</span>
    {
        <span class="hljs-built_in">string</span>[] requestedProperties = { <span class="hljs-string">"System.Devices.Aep.IsConnected"</span>,<span class="hljs-string">"System.Devices.Aep.DeviceAddress"</span>, <span class="hljs-string">"System.Devices.Aep.Bluetooth.Le.IsConnectable"</span>, <span class="hljs-string">"System.Devices.Aep.SignalStrength"</span>, <span class="hljs-string">"System.Devices.Aep.IsPresent"</span> };
        <span class="hljs-built_in">string</span> aqsAllBluetoothLEDevices = <span class="hljs-string">"(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")"</span>;


        DeviceWatcher deviceWatcher =
                DeviceInformation.CreateWatcher(
                    aqsAllBluetoothLEDevices,
                    requestedProperties,
                    DeviceInformationKind.AssociationEndpoint);

        deviceWatcher.Added += DeviceWatcher_Added;
        deviceWatcher.Updated += DeviceWatcher_Updated;
        deviceWatcher.Stopped += DeviceWatcher_Stopped;
        flag = <span class="hljs-literal">true</span>;
        <span class="hljs-built_in">long</span> l1 = Environment.TickCount + <span class="hljs-number">1</span> * timeOut * <span class="hljs-number">1000</span>;
        Task.Factory.StartNew(() =&gt;
        {
            <span class="hljs-keyword">while</span> (flag)
            {
                <span class="hljs-keyword">if</span> (Environment.TickCount &gt; l1)
                {
                    deviceWatcher.Stop();
                    <span class="hljs-keyword">return</span>;
                }
                <span class="hljs-keyword">else</span>
                {
                    Thread.Sleep(<span class="hljs-number">50</span>);
                }

            }

        });
        ScanResults.Clear();
        deviceWatcher.Start();
    }
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">DeviceWatcher_Added</span>(<span class="hljs-params">DeviceWatcher sender, DeviceInformation args</span>)</span>
    {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">string</span>.IsNullOrEmpty(args.Name)) { <span class="hljs-keyword">return</span>; }

        <span class="hljs-keyword">var</span> rssi = args.Properties.Single(d =&gt; d.Key == <span class="hljs-string">"System.Devices.Aep.SignalStrength"</span>).Value;
        <span class="hljs-keyword">if</span> (rssi == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">return</span>; }
        <span class="hljs-built_in">int</span> x1 = <span class="hljs-built_in">int</span>.Parse(rssi.ToString());

        <span class="hljs-keyword">if</span> (x1 &lt; <span class="hljs-number">-80</span>) { <span class="hljs-keyword">return</span>; }

        <span class="hljs-built_in">string</span> s1 = <span class="hljs-string">$"[<span class="hljs-subst">{x1}</span>] <span class="hljs-subst">{ (args.Name).PadLeft(<span class="hljs-number">30</span>, <span class="hljs-string">' '</span>)}</span> <span class="hljs-subst">{args.Id}</span>"</span>;

        Console.WriteLine(s1);
        <span class="hljs-keyword">if</span> (!Find(args.Id))
        {
            <span class="hljs-keyword">var</span> x = args.Properties;

            ScanResults.Add(<span class="hljs-keyword">new</span> ScanResult(args.Name, args.Id));
        }
    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">DeviceWatcher_Stopped</span>(<span class="hljs-params">DeviceWatcher sender, <span class="hljs-built_in">object</span> args</span>)</span>
    {
        OnScanResult?.Invoke(sender, <span class="hljs-keyword">new</span> BleScanResultEventArgs(ScanResults));
    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">DeviceWatcher_Updated</span>(<span class="hljs-params">DeviceWatcher sender, DeviceInformationUpdate args</span>)</span>
    {

    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task&lt;<span class="hljs-built_in">int</span>&gt; <span class="hljs-title">Connect</span>(<span class="hljs-params"><span class="hljs-built_in">string</span> mac, <span class="hljs-built_in">string</span> serviceId, <span class="hljs-built_in">string</span> writeId, <span class="hljs-built_in">string</span> readId</span>)</span>
    {
        Mac = mac.ToLower();
        ServiceID = serviceId.ToLower();
        WriteID = writeId.ToLower();
        ReadID = readId.ToLower();
        <span class="hljs-keyword">try</span>
        {
            BluetoothAdapter bluetoothAdapter = <span class="hljs-keyword">await</span> BluetoothAdapter.GetDefaultAsync();
            <span class="hljs-keyword">if</span> (bluetoothAdapter == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>; }

            <span class="hljs-built_in">byte</span>[] _Bytes1 = BitConverter.GetBytes(bluetoothAdapter.BluetoothAddress);<span class="hljs-comment">//ulong转换为byte数组</span>
            Array.Reverse(_Bytes1);
            <span class="hljs-built_in">string</span> macAddress = BitConverter.ToString(_Bytes1, <span class="hljs-number">2</span>, <span class="hljs-number">6</span>).Replace(<span class="hljs-string">'-'</span>, <span class="hljs-string">':'</span>).ToLower();
            <span class="hljs-built_in">string</span> Id = <span class="hljs-string">"BluetoothLE#BluetoothLE"</span> + macAddress + <span class="hljs-string">"-"</span> + Mac;
            Device = <span class="hljs-keyword">await</span> BluetoothLEDevice.FromIdAsync(Id);
            <span class="hljs-keyword">if</span> (Device == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">-2</span>; }

            GattDeviceServicesResult result = <span class="hljs-keyword">await</span> Device.GetGattServicesForUuidAsync(<span class="hljs-keyword">new</span> Guid(ServiceID));
            IEnumerable&lt;GattDeviceService&gt; lists = result.Services;
            <span class="hljs-keyword">if</span> (lists == <span class="hljs-literal">null</span> || lists.Count() == <span class="hljs-number">0</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">-3</span>; }

            Service = result.Services[<span class="hljs-number">0</span>];
            GattCharacteristicsResult w1 = <span class="hljs-keyword">await</span> Service.GetCharacteristicsForUuidAsync(<span class="hljs-keyword">new</span> Guid(WriteID));
            IEnumerable&lt;GattCharacteristic&gt; list2 = w1.Characteristics;
            <span class="hljs-keyword">if</span> (list2 == <span class="hljs-literal">null</span> || list2.Count() == <span class="hljs-number">0</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">-4</span>; }

            WriteCharacteristic = w1.Characteristics[<span class="hljs-number">0</span>];
            GattCharacteristicsResult r1 = <span class="hljs-keyword">await</span> Service.GetCharacteristicsForUuidAsync(<span class="hljs-keyword">new</span> Guid(ReadID));
            IEnumerable&lt;GattCharacteristic&gt; list3 = r1.Characteristics;
            <span class="hljs-keyword">if</span> (list3 == <span class="hljs-literal">null</span> || list3.Count() == <span class="hljs-number">0</span>) { <span class="hljs-keyword">return</span> <span class="hljs-number">-5</span>; }

            NotifyCharacteristic = r1.Characteristics[<span class="hljs-number">0</span>];
            NotifyCharacteristic.ProtectionLevel = GattProtectionLevel.Plain;
            NotifyCharacteristic.ValueChanged += Characteristic_ValueChanged;
            <span class="hljs-keyword">await</span> NotifyCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
            <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
        }
        <span class="hljs-keyword">catch</span>
        {
            <span class="hljs-keyword">return</span> <span class="hljs-number">-6</span>;
        }
    }

    <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;summary&gt;</span></span>
    <span class="hljs-comment"><span class="hljs-doctag">///</span> 发送数据接口</span>
    <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;/summary&gt;</span></span>
    <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;param name="characteristic"&gt;</span><span class="hljs-doctag">&lt;/param&gt;</span></span>
    <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;param name="data"&gt;</span><span class="hljs-doctag">&lt;/param&gt;</span></span>
    <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;returns&gt;</span><span class="hljs-doctag">&lt;/returns&gt;</span></span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task&lt;<span class="hljs-built_in">bool</span>&gt; <span class="hljs-title">Write</span>(<span class="hljs-params"><span class="hljs-built_in">byte</span>[] data</span>)</span>
    {
        <span class="hljs-keyword">if</span> (WriteCharacteristic == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; }


        <span class="hljs-built_in">int</span> count = <span class="hljs-number">20</span>;
        <span class="hljs-built_in">int</span> len = count;
        <span class="hljs-keyword">try</span>
        {
            <span class="hljs-keyword">for</span> (<span class="hljs-built_in">int</span> i = <span class="hljs-number">0</span>; i &lt; data.Length; i += count)
            {
                <span class="hljs-keyword">if</span> (i + count &gt; data.Length) { len = data.Length - i; }
                <span class="hljs-built_in">byte</span>[] b1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">byte</span>[len];
                Array.Copy(data, i, b1, <span class="hljs-number">0</span>, len);
                Console.WriteLine(<span class="hljs-string">$"发送 : "</span> + ByteToHex(b1));
                GattCommunicationStatus status = <span class="hljs-keyword">await</span> WriteCharacteristic.WriteValueAsync(CryptographicBuffer.CreateFromByteArray(b1), GattWriteOption.WriteWithoutResponse);
                <span class="hljs-keyword">if</span> (status != GattCommunicationStatus.Success) { <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; }
                <span class="hljs-keyword">else</span>
                {
                    Thread.Sleep(<span class="hljs-number">5</span>);
                }
            }
            <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        }
        <span class="hljs-keyword">catch</span> (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
        }

    }

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Characteristic_ValueChanged</span>(<span class="hljs-params">GattCharacteristic sender, GattValueChangedEventArgs args</span>)</span>
    {
        <span class="hljs-built_in">byte</span>[] data;
        CryptographicBuffer.CopyToByteArray(args.CharacteristicValue, <span class="hljs-keyword">out</span> data);
        <span class="hljs-built_in">string</span> str = BitConverter.ToString(data);
        OnRev?.Invoke(<span class="hljs-keyword">this</span>, <span class="hljs-keyword">new</span> BleEventArgs(data));
    }
    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-built_in">string</span> <span class="hljs-title">ByteToHex</span>(<span class="hljs-params"><span class="hljs-built_in">byte</span>[] b, <span class="hljs-built_in">bool</span> space = <span class="hljs-literal">true</span></span>)</span>
    {
        <span class="hljs-keyword">if</span> (b == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>; }
        StringBuilder sb = <span class="hljs-keyword">new</span> StringBuilder();
        <span class="hljs-keyword">for</span> (<span class="hljs-built_in">int</span> i = <span class="hljs-number">0</span>; i &lt; b.Length; i++)
        {
            sb.Append(b[i].ToString(<span class="hljs-string">"X2"</span>) + (space ? <span class="hljs-string">" "</span> : <span class="hljs-string">""</span>));
        }
        <span class="hljs-keyword">return</span> sb.ToString();
    }
}
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-built_in">delegate</span> <span class="hljs-keyword">void</span> <span class="hljs-title">BleRev</span>(<span class="hljs-params"><span class="hljs-built_in">object</span> sender, BleEventArgs e</span>)</span>;
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-built_in">delegate</span> <span class="hljs-keyword">void</span> <span class="hljs-title">BleScanResult</span>(<span class="hljs-params"><span class="hljs-built_in">object</span> sender, BleScanResultEventArgs e</span>)</span>;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BleScanResultEventArgs</span> : <span class="hljs-title">EventArgs</span>
{
    <span class="hljs-keyword">public</span> List&lt;ScanResult&gt; ScanResults;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">BleScanResultEventArgs</span>(<span class="hljs-params">List&lt;ScanResult&gt; scanResults</span>)</span>
    {
        <span class="hljs-keyword">this</span>.ScanResults = scanResults;
    }
}
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ScanResult</span>
{
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">string</span> Name { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">string</span> Mac { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">string</span> ID { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ScanResult</span>(<span class="hljs-params"><span class="hljs-built_in">string</span> name, <span class="hljs-built_in">string</span> id</span>)</span>
    {
        <span class="hljs-keyword">this</span>.Name = name;

        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">string</span>.IsNullOrEmpty(Name))
        {
            Name = <span class="hljs-string">"未知"</span>;
        }
        <span class="hljs-keyword">this</span>.ID = id;

        <span class="hljs-built_in">string</span>[] s1 = id.Split(<span class="hljs-string">'-'</span>);
        <span class="hljs-keyword">if</span> (s1.Length == <span class="hljs-number">2</span>)
        {
            <span class="hljs-keyword">this</span>.Mac = s1[<span class="hljs-number">1</span>];
        }
        <span class="hljs-keyword">else</span>
        {
            <span class="hljs-keyword">this</span>.Mac = <span class="hljs-string">""</span>;
        }
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-built_in">string</span> <span class="hljs-title">ToString</span>()</span>
    {
        <span class="hljs-comment">//return $"{Name}\t{Mac}\t{ID}";</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">$"<span class="hljs-subst">{Name}</span>\t<span class="hljs-subst">{Mac}</span>"</span>;
    }
}
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BleEventArgs</span> : <span class="hljs-title">EventArgs</span>
{
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">byte</span>[] Data { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">BleEventArgs</span>(<span class="hljs-params"><span class="hljs-built_in">byte</span>[] data</span>)</span>
    {
        <span class="hljs-keyword">this</span>.Data = data;
    }

}
</code></pre>
<p>调用方式</p>
<p>扫描：</p>
<p>lb = new LanBle();<br>
lb.OnScanResult += Lb_OnScanResult;<br>
lb.Scan();</p>
<p>private void Lb_OnScanResult(object sender, BleScanResultEventArgs e)<br>
{<br>
foreach (var item in e.ScanResults)<br>
{<br>
AppendText(item.ToString(), false);<br>
}</p>
<pre class="highlighter-hljs" highlighted="true"><code class="highlighter-hljs hljs language-markdown"><span class="hljs-code">    }
</span></code></pre>
<p>连接：</p>
<p>LanBle lb = new LanBle();<br>
lb.OnRev += Lb_OnRev;<br>
int iRev = await lb.Connect(mac, _serviceGuid, _writeCharacteristicGuid, _notifyCharacteristicGuid);<br>
bool flag = iRev == 0;</p>
<p>发送数据：</p>
<p>private async Task<bool> Write(byte[] bSend)<br>
{<br>
bool flag = false;<br>
string sSend = Fun.ByteToHex(bSend);<br>
if (lb != null &amp;&amp; lb.Service != null)<br>
{<br>
lTime = Environment.TickCount;<br>
flag = await lb.Write(bSend);<br>
AppendText($"Send ： {sSend}");<br>
Console.WriteLine(flag);<br>
sRev = "";<br>
}<br>
Console.WriteLine($"发送【{(flag ? "成功" : "失败")}】：{sSend }");<br>
return flag;<br>
}</bool></p>
<p>收到数据：<br>
private void Lb_OnRev(object sender, BleEventArgs e)<br>
{<br>
byte[] data = e.Data;<br>
}</p>

</div>
<div class="clear"></div>
<div id="blog_post_info_block" role="contentinfo">
<div id="EntryTag">
    标签: 
            <a href="https://www.cnblogs.com/mycls/tag/WinForm%20BlueToothLE%20C%23%20%E8%93%9D%E7%89%99%20%E4%BD%8E%E5%8A%9F%E8%80%97/">WinForm BlueToothLE C# 蓝牙 低功耗</a>,             <a href="https://www.cnblogs.com/mycls/tag/c%23/">c#</a></div>

    <div id="blog_post_info">
<div id="green_channel">
        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(15945845,cb_blogId,1);green_channel_success(this,&#39;谢谢推荐！&#39;);">好文要顶</a>
        <a id="green_channel_follow" onclick="follow(&#39;d1115e3a-1c48-e311-8d02-90b11c0b17d6&#39;);" href="javascript:void(0);">关注我</a>
    <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
    <a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/icon_weibo_24.png" alt=""></a>
    <a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/wechat.png" alt=""></a>
</div>
<div id="author_profile">
    <div id="author_profile_info" class="author_profile_info">
            <a href="https://home.cnblogs.com/u/mycls/" target="_blank"><img src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/sample_face.gif" class="author_avatar" alt=""></a>
        <div id="author_profile_detail" class="author_profile_info">
            <a href="https://home.cnblogs.com/u/mycls/">mycls</a><br>
            <a href="https://home.cnblogs.com/u/mycls/followers/">粉丝 - <span class="follower-count">2</span></a>
            <a href="https://home.cnblogs.com/u/mycls/followees/">关注 - <span class="following-count">21</span></a><br>
        </div>
    </div>
    <div class="clear"></div>
    <div id="author_profile_honor"></div>
    <div id="author_profile_follow" class="follow-tip">
                <a href="javascript:void(0);" onclick="follow(&#39;d1115e3a-1c48-e311-8d02-90b11c0b17d6&#39;);return false;">+加关注</a>
    </div>
</div>
<div id="div_digg">
    <div class="diggit" onclick="votePost(15945845,&#39;Digg&#39;)">
        <span class="diggnum" id="digg_count">1</span>
    </div>
    <div class="buryit" onclick="votePost(15945845,&#39;Bury&#39;)">
        <span class="burynum" id="bury_count">0</span>
    </div>
    <div class="clear"></div>
    <div class="diggword" id="digg_tips">
    </div>
</div>

<script type="text/javascript">
    currentDiggType = 0;
</script></div>
    <div class="clear"></div>
    <div id="post_next_prev"></div>
</div>
            </div>
            <div class="postDesc">posted @ 
<span id="post-date" data-date-updated-tip="disable" data-date-updated="2022-02-28 15:59">2022-02-28 15:33</span>&nbsp;
<a href="https://www.cnblogs.com/mycls/">mycls</a>&nbsp;
阅读(<span id="post_view_count">1471</span>)&nbsp;
评论(<span id="post_comment_count">4</span>)&nbsp;
<a href="https://i.cnblogs.com/EditArticles.aspx?postid=15945845" rel="nofollow">编辑</a>&nbsp;
<a href="javascript:void(0)" onclick="AddToWz(15945845);return false;">收藏</a>&nbsp;
<a href="javascript:void(0)" onclick="reportManager.report({ currentUserId: &#39;&#39;, targetType: &#39;blogPost&#39;, targetId: &#39;15945845&#39;, targetLink: &#39;https://www.cnblogs.com/mycls/articles/15945845.html&#39;, title: &#39;WinForm低功耗蓝牙通信BlueToothLE C#&#39; })">举报</a></div>
        </div>
        
<script>
    var cb_entryId = 15945845, cb_entryCreatedDate = '2022-02-28 15:33', cb_postType = 2, cb_postTitle = 'WinForm低功耗蓝牙通信BlueToothLE C#';
    var allowComments = true, cb_blogId = 193221, cb_blogApp = 'mycls', cb_blogUserGuid = 'd1115e3a-1c48-e311-8d02-90b11c0b17d6';
    mermaidRender.render()
    markdown_highlight()
    zoomManager.apply("#cnblogs_post_body img:not(.code_img_closed):not(.code_img_opened)");
    updatePostStats(
            [cb_entryId],
            function(id, count) { $("#post_view_count").text(count) },
            function(id, count) { $("#post_comment_count").text(count) })
</script>
        <a id="!comments"></a>
<div id="blog-comments-placeholder"></div>
<div id="comment_form" class="commentform">
    <a name="commentform"></a>
    <div id="divCommentShow"></div>
    <div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="https://www.cnblogs.com/mycls/articles/15945845.html#" onclick="return RefreshPage();">刷新页面</a><a href="https://www.cnblogs.com/mycls/articles/15945845.html#top">返回顶部</a></div>
    <div id="comment_form_container" style="visibility: visible;"><div class="login_tips">
    登录后才能查看或发表评论，立即 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return account.login(&#39;!comments&#39;);">登录</a> 或者
    <a href="https://www.cnblogs.com/">逛逛</a> 博客园首页
</div>
</div>
    <div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
        <div id="cnblogs_ch"></div>
    <div id="opt_under_post"></div>
    <div id="cnblogs_c1" class="under-post-card">
            <div id="div-gpt-ad-1592365906576-0" style="width: 300px; height: 250px;" data-google-query-id="COiZ19Skmf0CFU3KFgUdV9MMxg"><div id="google_ads_iframe_/1090369/C1_0__container__" style="border: 0pt none; display: inline-block; width: 300px; height: 250px;"><iframe frameborder="0" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/container.html" id="google_ads_iframe_/1090369/C1_0" title="3rd party ad content" name="" scrolling="no" marginwidth="0" marginheight="0" width="300" height="250" data-is-safeframe="true" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" role="region" aria-label="Advertisement" tabindex="0" data-google-container-id="1" style="border: 0px; vertical-align: bottom;" data-load-complete="true"></iframe></div></div>
    </div>
    <div id="under_post_card1"><div class="under-post-card">
<b>编辑推荐：</b>
<br>

· <a href="https://www.cnblogs.com/linvanda/p/17120205.html" target="_blank">我已经受够了“系统异常”！</a>
    <br>
· <a href="https://www.cnblogs.com/huangxincheng/p/17115916.html" target="_blank">记一次 .NET 某游戏网站 CPU 爆高分析</a>
    <br>
· <a href="https://www.cnblogs.com/jackyfei/p/17107742.html" target="_blank">探索 ABP 基础架构的横切关注点</a>
    <br>
· <a href="https://www.cnblogs.com/eryuan/p/17109391.html" target="_blank">一次生产环境 CPU 占用高的排查 </a>
    <br>
· <a href="https://www.cnblogs.com/coco1s/p/17107807.html" target="_blank">现代图片性能优化及体验优化指南</a>
    <br>
</div></div>
    <div id="under_post_card2"><div class="itnews under-post-card">
    <b>阅读排行：</b>
    <br>
 ·          <a href="https://www.cnblogs.com/niumoo/p/17121504.html" target="_blank">你好 ChatGPT, 帮我看下这段代码有什么问题？</a>
        <br>
 ·          <a href="https://www.cnblogs.com/linvanda/p/17120205.html" target="_blank">我已经受够了“系统异常”！</a>
        <br>
 ·          <a href="https://www.cnblogs.com/strick/p/17060135.html" target="_blank">我好像找到了点学习英文的技巧</a>
        <br>
 ·          <a href="https://www.cnblogs.com/sherrywasp/p/17118372.html" target="_blank">我让 ChatGPT 写了个 ChatGPT</a>
        <br>
 ·          <a href="https://www.cnblogs.com/zzyang/p/17119268.html" target="_blank">用Redis实现延迟队列，我研究了两种方案，发现并不简单</a>
        <br>
</div></div>
    <div id="HistoryToday" class="under-post-card"></div>
    <script type="text/javascript">
        var commentManager = new blogCommentManager();
        commentManager.renderComments(0);
        fixPostBody();
        window.footnoteTipManager.generateFootnoteTips();

            window.tocManager.displayDisableTocTips = false;
            window.tocManager.generateToc();
            
                setTimeout(function() { countViews(cb_blogId, cb_entryId); }, 50);
            
            deliverT2();
            deliverC1C2();
            loadNewsAndKb();
            
                LoadPostCategoriesTags(cb_blogId, cb_entryId);
            
            LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
            GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
            loadOptUnderPost();
            GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);
                </script>
</div>

    </div>
</div>
            </div>
        </div>

        <div id="sideBar">
            <div id="sideBarMain">
                <div id="sidebar_news" class="newsItem">
<h3 class="catListTitle">公告</h3>

<div id="blog-news">
    
    <div id="profile_block">
        昵称：
        <a href="https://home.cnblogs.com/u/mycls/">
            mycls
        </a>
        <br>
        园龄：
        <a href="https://home.cnblogs.com/u/mycls/" title="入园时间：2013-11-08">
            9年3个月
        </a>
        <br>
        粉丝：
        <a class="follower-count" href="https://home.cnblogs.com/u/mycls/followers/">
            2
        </a>
        <br>
        关注：
        <a class="folowing-count" href="https://home.cnblogs.com/u/mycls/followees/">
            21
        </a>
        <div id="p_b_follow" class="follow-tip">
<a href="javascript:void(0)" onclick="follow(&#39;d1115e3a-1c48-e311-8d02-90b11c0b17d6&#39;)">+加关注</a></div>
        <script>getFollowStatus('d1115e3a-1c48-e311-8d02-90b11c0b17d6');</script>
    </div>
</div></div>
<div id="sidebar_c3"></div>
                <div id="calendar"><div id="blog-calendar" style="">

<table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="Calendar" border="0">
    <tbody>
        <tr>
            <td colspan="7">
                <table class="CalTitle" cellspacing="0" border="0">
                    <tbody>
                        <tr>
                            <td class="CalNextPrev">
                                <a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2023/01/16&#39;); return false;">&lt;</a>
                            </td>
                            <td align="center">2023年2月</td>
                            <td align="right" class="CalNextPrev">
                                <a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2023/03/16&#39;); return false;">&gt;</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    <tr>
        <th class="CalDayHeader" align="center" abbr="日" scope="col">日</th>
        <th class="CalDayHeader" align="center" abbr="一" scope="col">一</th>
        <th class="CalDayHeader" align="center" abbr="二" scope="col">二</th>
        <th class="CalDayHeader" align="center" abbr="三" scope="col">三</th>
        <th class="CalDayHeader" align="center" abbr="四" scope="col">四</th>
        <th class="CalDayHeader" align="center" abbr="五" scope="col">五</th>
        <th class="CalDayHeader" align="center" abbr="六" scope="col">六</th>
    </tr>
            <tr>
                            <td class="CalOtherMonthDay" align="center">29</td>
                            <td class="CalOtherMonthDay" align="center">30</td>
                            <td class="CalOtherMonthDay" align="center">31</td>
                        <td class="" align="center">
                            1
                        </td>
                        <td class="" align="center">
                            2
                        </td>
                        <td class="" align="center">
                            3
                        </td>
                    <td class="CalWeekendDay" align="center">
                        4
                    </td>
            </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            5
                        </td>
                            <td class="" align="center">
                                6
                            </td>
                            <td class="" align="center">
                                7
                            </td>
                            <td class="" align="center">
                                8
                            </td>
                            <td class="" align="center">
                                9
                            </td>
                            <td class="" align="center">
                                10
                            </td>
                        <td class="CalWeekendDay" align="center">
                            11
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            12
                        </td>
                            <td class="" align="center">
                                13
                            </td>
                            <td class="" align="center">
                                14
                            </td>
                            <td class="" align="center">
                                15
                            </td>
                            <td class="CalTodayDay" align="center">
                                16
                            </td>
                            <td class="" align="center">
                                17
                            </td>
                        <td class="CalWeekendDay" align="center">
                            18
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            19
                        </td>
                            <td class="" align="center">
                                20
                            </td>
                            <td class="" align="center">
                                21
                            </td>
                            <td class="" align="center">
                                22
                            </td>
                            <td class="" align="center">
                                23
                            </td>
                            <td class="" align="center">
                                24
                            </td>
                        <td class="CalWeekendDay" align="center">
                            25
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            26
                        </td>
                            <td class="" align="center">
                                27
                            </td>
                            <td class="" align="center">
                                28
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                1
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                2
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                3
                            </td>
                        <td class="CalOtherMonthDay" align="center">
                            4
                        </td>
                </tr>
                <tr>
                        <td class="CalOtherMonthDay" align="center">
                            5
                        </td>
                            <td class="CalOtherMonthDay" align="center">
                                6
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                7
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                8
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                9
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                10
                            </td>
                        <td class="CalOtherMonthDay" align="center">
                            11
                        </td>
                </tr>
    </tbody>
</table></div></div>                
                <script>loadBlogDefaultCalendar();</script>
                <div id="leftcontentcontainer">
                    <!-- begin:SingleColumn -->
                    <div id="blog-sidecolumn"><!-- 搜索 -->
<div id="sidebar_search" class="sidebar-block">
    <div id="sidebar_search" class="mySearch">
        <h3 class="catListTitle">搜索</h3>
        <div id="sidebar_search_box">
            <div id="widget_my_zzk" class="div_my_zzk">
                <input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="找找看" id="btnZzk" class="btn_my_zzk">
            </div>
            <div id="widget_my_google" class="div_my_zzk">
                <input type="text" name="google_q" id="google_q" onkeydown="return google_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="google_go()" type="button" value="谷歌搜索" class="btn_my_zzk">
            </div>
        </div>
    </div>
</div>

<!-- 常用链接 -->
<div id="sidebar_shortcut" class="sidebar-block">
<h3 class="catListTitle">
常用链接
</h3>
<ul>
    <li><a href="https://www.cnblogs.com/mycls/p/" title="我的博客的随笔列表">我的随笔</a></li>
<li><a href="https://www.cnblogs.com/mycls/MyComments.html" title="我的发表过的评论列表">我的评论</a></li>
<li><a href="https://www.cnblogs.com/mycls/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li>
<li><a href="https://www.cnblogs.com/mycls/comments" title="我的博客的评论列表">最新评论</a></li>
<li><a href="https://www.cnblogs.com/mycls/tag/" title="我的博客的标签列表">我的标签</a></li>

</ul>
</div>

<!-- 最新随笔 -->


<!-- 我的标签 -->
<div id="sidebar_toptags" class="sidebar-block"><div class="catListTag">
    <h3 class="catListTitle"><a href="https://www.cnblogs.com/mycls/tag/" class="sidebar-card-title-a">我的标签</a></h3>
    <ul>
                <li>
            <a href="https://www.cnblogs.com/mycls/tag/c%23/">c#<span class="tag-count">(2)</span></a>
        </li>
        <li>
            <a href="https://www.cnblogs.com/mycls/tag/%E9%A2%9C%E8%89%B2/">颜色<span class="tag-count">(1)</span></a>
        </li>
        <li>
            <a href="https://www.cnblogs.com/mycls/tag/%E5%AD%97%E7%AC%A6%E4%B8%B2/">字符串<span class="tag-count">(1)</span></a>
        </li>
        <li>
            <a href="https://www.cnblogs.com/mycls/tag/%E8%BD%AC%E6%8D%A2/">转换<span class="tag-count">(1)</span></a>
        </li>
        <li>
            <a href="https://www.cnblogs.com/mycls/tag/advtree%20CopySelectTree/">advtree CopySelectTree<span class="tag-count">(1)</span></a>
        </li>
        <li>
            <a href="https://www.cnblogs.com/mycls/tag/WinForm%20BlueToothLE%20C%23%20%E8%93%9D%E7%89%99%20%E4%BD%8E%E5%8A%9F%E8%80%97/">WinForm BlueToothLE C# 蓝牙 低功耗<span class="tag-count">(1)</span></a>
        </li>
    

    </ul>
</div>
</div>

<!-- 积分与排名 -->


<!-- 随笔分类、随笔档案、文章分类、新闻分类、相册、链接 -->
<div id="sidebar_categories">

    <div class="catListPostArchive">
        <h3 class="catListTitle">
            
随笔档案


        </h3>
        <ul>
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/mycls/archive/2021/08.html" class="category-item-link" rel="" target="">2021年8月(1)</a>

                    
                </li>
                                            <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/mycls/archive/2021/07.html" class="category-item-link" rel="" target="">2021年7月(1)</a>

                    
                </li>
                                            <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/mycls/archive/2019/04.html" class="category-item-link" rel="" target="">2019年4月(2)</a>

                    
                </li>
                                            <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/mycls/archive/2017/12.html" class="category-item-link" rel="" target="">2017年12月(1)</a>

                    
                </li>
                                            <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/mycls/archive/2017/11.html" class="category-item-link" rel="" target="">2017年11月(1)</a>

                    
                </li>
                                            <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/mycls/archive/2017/03.html" class="category-item-link" rel="" target="">2017年3月(1)</a>

                    
                </li>
                                            <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/mycls/archive/2016/09.html" class="category-item-link" rel="" target="">2016年9月(3)</a>

                    
                </li>
                                        
        </ul>
    </div></div>

<!-- 最新评论 -->
<!-- 阅读排行榜 -->
<div id="sidebar_topviewedposts" class="sidebar-block">
<div id="topview_posts_wrap">
    <h3 class="catListTitle">
        <a href="https://www.cnblogs.com/mycls/most-viewed" class="sidebar-card-title-a">
    阅读排行榜
</a>

    </h3>
    <div id="TopViewPostsBlock">
        <ul style="word-break:break-all">
                    <li>
                        <a href="https://www.cnblogs.com/mycls/p/5861185.html">
                            1. c# 颜色字符串转换为颜色(6013)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/mycls/p/6550406.html">
                            2. DataGridView 区域 复制 粘贴 恢复 同Excel(1481)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/mycls/p/5922431.html">
                            3. linux cgroup(844)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/mycls/p/10738842.html">
                            4. DataGridView DataGridViewCheckBoxColumn选中更改问题(401)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/mycls/p/10738816.html">
                            5. advtree复制选中项(371)
                        </a>
                    </li>
        </ul>
    </div>
</div></div>

<!-- 评论排行榜 -->
<div id="sidebar_topcommentedposts" class="sidebar-block"></div>

<!-- 推荐排行榜 -->
<div id="sidebar_topdiggedposts" class="sidebar-block"></div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap" class="RecentComment">
    <h3 class="catListTitle"><a href="https://www.cnblogs.com/mycls/comments" class="sidebar-card-title-a">最新评论</a></h3>    
    <div class="RecentCommentBlock">
        <ul>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/mycls/articles/15945845.html">1. Re:WinForm低功耗蓝牙通信BlueToothLE C#</a></li>
                <li class="recent_comment_body">@孤独氏强者 没有遇到过，只是遇到扫描的时候，之前连接过的设备还在列表中的问题...</li>
                <li class="recent_comment_author">--mycls</li>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/mycls/articles/15945845.html">2. Re:WinForm低功耗蓝牙通信BlueToothLE C#</a></li>
                <li class="recent_comment_body"><p>楼主有遇到蓝牙调用断开函数，实际蓝牙还是显示连接状态问题吗</p>
</li>
                <li class="recent_comment_author">--孤独氏强者</li>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/mycls/articles/15945845.html">3. Re:WinForm低功耗蓝牙通信BlueToothLE C#</a></li>
                <li class="recent_comment_body">@『DYLIKE』 这是系统的，添加引用就有了...</li>
                <li class="recent_comment_author">--mycls</li>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/mycls/articles/15945845.html">4. Re:WinForm低功耗蓝牙通信BlueToothLE C#</a></li>
                <li class="recent_comment_body"><p>不错,非常有用,就是缺少Windows.Devices.Bluetooth的dll文件链接</p>
</li>
                <li class="recent_comment_author">--『DYLIKE』</li>
        </ul>
    </div>
</div></div>


</div>
                    <script>loadBlogSideColumn();</script>
                    <!-- end:  SingleColumn -->
                </div>
            </div>
        </div>
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
    <div id="footer">
        <!--done-->
Copyright © 2023 mycls
<br><span id="poweredby">Powered by .NET 7.0 on Kubernetes</span>

    </div>
</div>


    

    <input type="hidden" id="antiforgery_token" value="CfDJ8GXQNXLgcs5PrnWvMs4xAGOiiXLZSwnBGSNJO2rchedPkh9a6dakSeix1UT6fUsIvrSeR38jl8gtRmgynNh9X22on9vzStMYk-8pHEXB4jE1b1sK4Ot_dPj-_glXWSKQ3L-1GEq8qXCV4dEKT357Dpw">
    <script async="" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/js"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    var kv = getGACustom();
    if (kv) {
        gtag('set', kv);
    }
    gtag('config', 'UA-476124-1');
</script>
<script defer="" src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/hm.js.下载"></script><iframe src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/container(1).html" style="visibility: hidden; display: none;"></iframe>

<iframe src="./WinForm低功耗蓝牙通信BlueToothLE C# - mycls - 博客园_files/aframe.html" width="0" height="0" style="display: none;"></iframe></body></html>